package com.ruoyi.driver.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.driver.domain.TbDriver;
import com.ruoyi.driver.service.ITbDriverService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
0 *
 * @author wuxiao
 * @date 2024-08-20
 */
@RestController
@RequestMapping("/driver")
public class TbDriverController extends BaseController
{
    @Autowired
    private ITbDriverService tbDriverService;






    /**
     * 查询司机列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TbDriver tbDriver)
    {
        startPage();
        List<TbDriver> list = tbDriverService.selectTbDriverList(tbDriver);
        return getDataTable(list);
    }

    /**
     * 导出司机列表
     */
    @Log(title = "司机", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbDriver tbDriver)
    {
        List<TbDriver> list = tbDriverService.selectTbDriverList(tbDriver);
        ExcelUtil<TbDriver> util = new ExcelUtil<TbDriver>(TbDriver.class);
        util.exportExcel(response, list, "司机数据");
    }

    /**
     * 获取司机详细信息
     */
    @GetMapping(value = "/{driverId}")
    public AjaxResult getInfo(@PathVariable("driverId") Long driverId)
    {
        return AjaxResult.success(tbDriverService.selectTbDriverByDriverId(driverId));
    }

    /**
     * 新增司机
     */
    @Log(title = "司机", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbDriver tbDriver)
    {
        return toAjax(tbDriverService.insertTbDriver(tbDriver));
    }

    /**
     * 修改司机
     */
    @Log(title = "司机", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbDriver tbDriver)
    {
        return toAjax(tbDriverService.updateTbDriver(tbDriver));
    }

    /**
     * 删除司机
     */
    @Log(title = "司机", businessType = BusinessType.DELETE)
	@DeleteMapping("/{driverIds}")
    public AjaxResult remove(@PathVariable Long[] driverIds)
    {
        return toAjax(tbDriverService.deleteTbDriverByDriverIds(driverIds));
    }
}
